package org.system.core.controller.monitor;

import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.system.core.annotation.Log;
import org.system.core.common.PageResult;
import org.system.core.common.Result;
import org.system.core.domain.entity.SysOperLog;
import org.system.core.enums.BusinessType;
import org.system.core.service.monitor.SysOperLogService;
import org.system.core.utils.PageUtils;

import java.util.List;

/**
 * @author baoRoot
 */
@RestController
@Api(tags = {"操作日志模块"})
@RequestMapping("/monitor/operlog")
public class SysOperLogController {

    private static final Logger logger = LoggerFactory.getLogger(SysOperLogController.class);

    @Autowired
    private SysOperLogService sysOperLogService;

    @GetMapping("/list")
    @ApiOperation("获取操作日志列表")
    @PreAuthorize("@ss.hasPermi('monitor:operlog:list')")
    public PageResult<SysOperLog> list(SysOperLog sysOperLog) {
        logger.info("获取操作日志列表: {}", sysOperLog);
        PageUtils.startPage();
        List<SysOperLog> sysOperLogs = sysOperLogService.selectOperLogList(sysOperLog);
        return PageResult.ok(new PageInfo<>(sysOperLogs));
    }

    @DeleteMapping("/{operIds}")
    @ApiOperation("删除操作日志")
    @PreAuthorize("@ss.hasPermi('monitor:operlog:remove')")
    @Log(title = "操作日志", businessType = BusinessType.DELETE)
    public Result<String> deleteOperLog(@PathVariable Long[] operIds) {
        logger.info("删除操作日志： {}", operIds);
        sysOperLogService.deleteOperLogByIds(operIds);
        return Result.ok();
    }

    @DeleteMapping("/clean")
    @ApiOperation("清空操作日志")
    @PreAuthorize("@ss.hasPermi('monitor:operlog:remove')")
    @Log(title = "操作日志", businessType = BusinessType.CLEAN)
    public Result<String> cleanOperLog() {
        logger.info("清空操作日志");
        sysOperLogService.cleanOperLog();
        return Result.ok();
    }

}
